#include "matrices.h"

/**
** @brief Test if the block is a road
**
** @param Block
**
** @return 0/1
*/
char is_road(e_block b)
{
    return (b > B_EMPTY && b < B_ROAD_LAST);
}

static void check_start_end(s_object *object, char c, int i, int j)
{
    if (c == '0')
    {
        object->src[0] = i;
        object->src[1] = j;

    }
    else if (c == '1')
    {
        object->dst[0] = i;
        object->dst[1] = j;

    }
}

/**
 ** @brief Fills a matrix with the content of a file.
 **
 ** @param String path of the file
 ** @param Matrix of char
 */
void get_mat(char *path, s_object *object)
{
    int     i;
    int     j;
    char    c;
    FILE    *f;

    if ((f = fopen(path, "r")))
    {
        for (i = 0; i < MAT_H; i++)
        {
            for (j = 0; j < MAT_W; j++)
            {
                c = fgetc(f);
                check_start_end(object, c, i, j);
                object->mat[i][j] = c;
            }
            if (fgetc(f) != '\n')
                printf("Matrice chargée au mauvais format.\n");
        }
        fclose(f);
    }
}
